package tuanvn.iti.vn;

import java.util.List;
import java.util.Random;

import mrtran.iti.vn.Main;
import mrtran.iti.vn.Main.GameView;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Rect;
import android.location.Address;

public class SpriteMonster3 {

	private GameView gameView3;
	private Bitmap bmpmonster3;
	private int widthMonster;
	private int heightMonster;
	private static final int BMP_COLUMNS_MONSTER = 7;
	private static final int BMP_ROWS_MONSTER = 2;
	public static int distance3;
	public static int monsterWidth3,widthLuffyMonster3;
	public static int xMonsterCenter3,yMonsterCenter3;
	private List<SpriteMonster3> spriteMonster3;
	
	int currentFrame3 = 0;
	public static int xSpeedMonster3 = 10;
	private static int ySpeedMonster3 = 0;
	int xMonster3=Main.SCREENWIDTH+Main.SCREENWIDTH,yMonster3 = Main.SCREENHEIGHT/2;
	int[] DIRECTION_TO_ANIMATION_MONSTER3 = {0,1};

	
	public SpriteMonster3(GameView gameView3, Bitmap bmpmonster3,List<SpriteMonster3> spriteMonster3) {
		this.gameView3 = gameView3;
		this.bmpmonster3 = bmpmonster3;
		this.distance3 = distance3;
		this.spriteMonster3 = spriteMonster3;
		this.widthMonster = bmpmonster3.getWidth() / BMP_COLUMNS_MONSTER;
		this.heightMonster = bmpmonster3.getHeight() / BMP_ROWS_MONSTER;	
	}

	private void update() {	
			xMonster3-=xSpeedMonster3;
		    currentFrame3 = ++currentFrame3 % BMP_COLUMNS_MONSTER;	
			xMonsterCenter3 = xMonster3+widthMonster/2;
			yMonsterCenter3 = yMonster3+heightMonster/2;
			monsterWidth3 = widthMonster/2;	  		
		}

	public void onDraw(Canvas canvas) {
		update();
		int srcX3 = currentFrame3 * widthMonster;
		int srcY3 = getAnimationRowMonster3() * heightMonster;
		Rect src3 = new Rect(srcX3, srcY3, srcX3 + widthMonster, srcY3
				+ heightMonster);
		Rect dst3 = new Rect(xMonster3, yMonster3, xMonster3 + widthMonster,
				yMonster3 + heightMonster);
		canvas.drawBitmap(bmpmonster3, src3, dst3, null);
		
	}

	private int getAnimationRowMonster3() {
		double dirDouble = (Math.atan2(xSpeedMonster3, ySpeedMonster3)
				/ (Math.PI / 2) + 2);
		int direction = (int) Math.round(dirDouble) % BMP_ROWS_MONSTER;
		return DIRECTION_TO_ANIMATION_MONSTER3[direction];
	}

}
